package article

import (
	"blog/app/models"
	"blog/app/models/user"
	"blog/pkg/route"
	"strconv"
)

type Article struct {
	models.BaseModel
	Title      string `gorm:"column:title;type:varchar(255)" valid:"title"`
	Body       string `gorm:"column:body;type:varchar(255)" valid:"body"`
	UserID     uint64 `gorm:"not null;index"`
	User       user.User
	CategoryID uint64 `gorm:"not null;default:4;index"`
}

func (article Article) Link() string {
	return route.Name2URL("articles.show", "id", strconv.FormatUint(article.ID, 10))
}

//CreatedDate 创建日期
func (article Article) CreatedDate() string {
	return article.CreatedAt.Format("2006-01-02")
}
